//
//  LRXPaySuccessController.m
//  路人侠
//
//  Created by zhangxulong on 5/16/16.
//  Copyright © 2016 zhangxulong. All rights reserved.
//

#import "LRXPaySuccessController.h"
#import "LRXMyHelpItemController.h"
@implementation LRXPaySuccessController

- (void)viewDidLoad
{
    self.navigationItem.title = @"支付成功";
    self.view.backgroundColor = [UIColor colorWithRed:239 green:239 blue:239];
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(popRootView)];
    
    
    UIImageView * headImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"paySuccess"]];
    headImage.frame = CGRectMake(0, 10 * hScale, MainScreenW, 250 * hScale);
    
    UIImageView * dgImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"dg"]];
    dgImage.frame = CGRectMake(86 * wScale, 57 * hScale, 97 * hScale, 97 * hScale);
    
    UILabel * subLabel = [[UILabel alloc]init];
    subLabel.text = @"买家已付款";
    subLabel.textColor = [UIColor whiteColor];
    subLabel.font = [UIFont systemFontOfSize:14];
    [subLabel sizeToFit];
    subLabel.center = CGPointMake(dgImage.center.x, CGRectGetMaxY(dgImage.frame) + 48 * hScale);
    
    
    [headImage addSubview:dgImage];
    [headImage addSubview:subLabel];
    
    [self.view addSubview:headImage];
    
    [self layoutContentView];
}

- (void)layoutContentView
{
    CGFloat fontSize = 28 * hScale;
    CGFloat viewX = 41 * wScale;
    
    
    UIView * contentView = [[UIView alloc]init];
    contentView.backgroundColor = [UIColor whiteColor];
    
    
    UILabel * sendAddr = [[UILabel alloc]init];
    sendAddr.frame = CGRectMake(viewX, 38 * hScale, 0, 0);
    sendAddr.text = @"收货地址：";
    sendAddr.font = [UIFont systemFontOfSize:fontSize];
    [sendAddr sizeToFit];
    [contentView addSubview:sendAddr];
    
    UILabel * sendAddrText = [[UILabel alloc]init];
    CGFloat fontSizeX = CGRectGetMaxX(sendAddr.frame) + 10 * wScale;
    CGFloat fontSizeW = MainScreenW - fontSizeX - 20 * wScale;
    CGSize fontSize2 = [self.sendTextStr boundingRectWithSize:CGSizeMake(fontSizeW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]} context:nil].size;
    
    sendAddrText.frame = CGRectMake(fontSizeX, sendAddr.frame.origin.y, fontSize2.width, fontSize2.height);
    sendAddrText.text = self.sendTextStr;
    sendAddrText.font = [UIFont systemFontOfSize:fontSize];
    sendAddrText.numberOfLines = 0;
    [contentView addSubview:sendAddrText];
    
    UILabel * sendHome = [[UILabel alloc]init];
    sendHome.text = @"送货上楼：";
    sendHome.font = [UIFont systemFontOfSize:fontSize];
    sendHome.frame = CGRectMake(viewX, CGRectGetMaxY(sendAddrText.frame) + 39 * hScale, 0, 0);
    [sendHome sizeToFit];
    [contentView addSubview:sendHome];
    
    
    UILabel * sendHomeText = [[UILabel alloc]init];
    sendHomeText.text = @"7A305";
    sendHomeText.font = [UIFont systemFontOfSize:fontSize];
    sendHomeText.frame = CGRectMake(CGRectGetMaxX(sendHome.frame) + 10 * wScale, sendHome.frame.origin.y, 0, 0);
    [sendHomeText sizeToFit];
    
    [contentView addSubview:sendHomeText];
    
    UIView * lineView = [[UIView alloc]init];
    lineView.backgroundColor = GraylineColor;
    lineView.frame = CGRectMake(viewX, CGRectGetMaxY(sendHomeText.frame) + 37 * hScale, MainScreenW - 2 * viewX, 2 * hScale);
    [contentView addSubview:lineView];
    
    
    UILabel * sum = [[UILabel alloc]init];
    NSString * sumStr = [NSString stringWithFormat:@"总价： %.2lf 元",self.sumMoney];
    sum.text = sumStr;
    sum.textColor = orangeColor;
    sum.font = [UIFont systemFontOfSize:fontSize];
    sum.frame = CGRectMake(41 * wScale, CGRectGetMaxY(lineView.frame) + 41 * hScale, 0, 0);
    [sum sizeToFit];
    
    [contentView addSubview:sum];
    
    UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setTitle:@"返回首页" forState:UIControlStateNormal];
    backBtn.titleLabel.font = [UIFont systemFontOfSize:27 * hScale];
    [backBtn setTitleColor:[UIColor colorWithRed:51 green:51 blue:51] forState:UIControlStateNormal];
    backBtn.layer.cornerRadius = 5 * hScale;
    backBtn.layer.borderColor = [UIColor colorWithRed:51 green:51 blue:51].CGColor;
    backBtn.layer.borderWidth = 2 * hScale;
    backBtn.frame = CGRectMake(84 * wScale, 302 * hScale, 201 * wScale, 68 * hScale);
    backBtn.tag = 1;
    [backBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton * checkItemBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [checkItemBtn setTitleColor:[UIColor colorWithRed:51 green:51 blue:51] forState:UIControlStateNormal];
    [checkItemBtn setTitle:@"查看订单" forState:UIControlStateNormal];
    checkItemBtn.titleLabel.font = [UIFont systemFontOfSize:27 * hScale];
    [checkItemBtn setTitleColor:[UIColor colorWithRed:51 green:51 blue:51] forState:UIControlStateNormal];
    checkItemBtn.layer.cornerRadius = 5 * hScale;
    checkItemBtn.layer.borderColor = [UIColor colorWithRed:51 green:51 blue:51].CGColor;
    checkItemBtn.layer.borderWidth = 2 * hScale;
    CGFloat checkItemBtnX = MainScreenW - 84 * wScale - 201 * wScale;
    checkItemBtn.frame = CGRectMake(checkItemBtnX, 302 * hScale, 201 * wScale, 68 * hScale);
    checkItemBtn.tag = 2;
    [checkItemBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [contentView addSubview:backBtn];
    [contentView addSubview:checkItemBtn];
    
    contentView.frame = CGRectMake(0, 280 * hScale, MainScreenW, CGRectGetMaxY(checkItemBtn.frame) + 34 * hScale);

    [self.view addSubview:contentView];
}
- (void)popRootView
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)buttonClick:(UIButton *)btn
{
    if (btn.tag == 1) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
    else
    {
        
//        [self.navigationController popToRootViewControllerAnimated:NO];
        [self.navigationController pushViewController:[LRXMyHelpItemController new] animated:YES];
    }
}

@end
